package net.kazed.nextaction.view;

import net.kazed.nextaction.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * Custom component - row item.
 * @author Koert Zeilstra
 */
public class RowItem extends RelativeLayout {
   
   public RowItem(final Context context, final AttributeSet attrs) {
      super(context, attrs);
      LayoutInflater.from(context).inflate(R.layout.custom_row_item, this, true);
      
      TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.rowItem, 0, 0);
      
      String text = array.getString(R.styleable.rowItem_title);
      if (text != null) {
         TextView title = (TextView) findViewById(R.id.title);
         title.setText(text);
      }
      
      TextView subTitleText = (TextView) findViewById(R.id.subtitle);
      String subTitleString = array.getString(R.styleable.rowItem_subtitle);
      if (subTitleString == null) {
          subTitleText.setText("");
      } else {
         subTitleText.setText(subTitleString);
      }
      
      ImageView icon = (ImageView) findViewById(R.id.icon);
      Drawable image = array.getDrawable(R.styleable.rowItem_icon);
      if (image == null) {
          icon.setVisibility(INVISIBLE);
      } else {
         icon.setImageDrawable(image);
      }
      array.recycle();
  }
}